---
sidebar_position: 42 # Use alphabetical order
---

# isWorkletFunction

`isWorkletFunction` checks if a function is a worklet function. It only works with Worklets Babel plugin enabled. Unless you are doing something with internals of Worklets you shouldn't need to use this function.

## Reference

```javascript
import { isWorkletFunction } from 'react-native-worklets';

const workletFunction = () => {
  'worklet';
  return 1;
};

const isWorkletFunction = isWorkletFunction(workletFunction);

console.log(isWorkletFunction); // true

const nonWorkletFunction = () => {
  return 1;
};

const isNonWorkletFunction = isWorkletFunction(nonWorkletFunction);

console.log(isNonWorkletFunction); // false
```

<details>
<summary>Type definitions</summary>

```typescript
type WorkletClosure = Record<string, unknown>;

export type WorkletStackDetails = [
  error: Error,
  lineOffset: number,
  columnOffset: number,
];

interface WorkletInitData {
  code: string;
  /** Only in dev builds. */
  location?: string;
  /** Only in dev builds. */
  sourceMap?: string;
  /** Only in dev builds. */
  version?: string;
}

interface WorkletProps {
  __closure: WorkletClosure;
  __workletHash: number;
  __initData: WorkletInitData;
  __init?: () => unknown;
  /** `__stackDetails` is removed after parsing. */
  __stackDetails?: WorkletStackDetails;
}

type WorkletFunction<
  TArgs extends unknown[] = unknown[],
  TReturn = unknown,
> = ((...args: TArgs) => TReturn) & WorkletProps;

function isWorkletFunction<
  Args extends unknown[] = unknown[],
  ReturnValue = unknown,
>(value: unknown): value is WorkletFunction<Args, ReturnValue>;
```

</details>

### Arguments

#### value

A function to check if it is a worklet function.

### Returns

`isWorkletFunction` returns a boolean value.

### Remarks

- Do not call it before the worklet is declared, as it will always return `false` then.

  ```ts
  isWorkletFunction(myWorklet); // Will always return false.

  function myWorklet() {
    'worklet';
  }
  ```
